/* ===========================================================
 * NetworkEvolutionPlugin : Cytoscape plugin for visualizing stages of
 * protein networks evolution.
 * ===========================================================
 *
 *
 * Project Info:  http://bioputer.mimuw.edu.pl/modevo/
 * Sources: http://code.google.com/p/misiek/
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
 * in the United States and other countries.]
 *
 * NetworkEvolutionPlugin  Copyright (C) 2008-2010
 * Authors:  Michal Wozniak (code) (m.wozniak@mimuw.edu.pl)
 *           Janusz Dutkowski (idea, data) (j.dutkowski@mimuw.edu.pl)
 *           Jerzy Tiuryn (supervisor) (tiuryn@mimuw.edu.pl)
 */

package ppine.ui.dataloading;

import cytoscape.Cytoscape;
import java.util.Map;
import javax.swing.JFrame;
import ppine.io.AbstractDataReader;
import ppine.io.listeners.ExperimentsLoadingErrorsListener;
import ppine.io.listeners.FamiliesLoadingErrorsListener;
import ppine.io.listeners.InteractionsLoadingErrorsListener;
import ppine.io.listeners.SpeciesLoadingErrorsListener;
import ppine.logicmodel.controllers.DataHandle;
import ppine.logicmodel.controllers.ProjectorInfoCalculator;
import ppine.logicmodel.structs.SpeciesTreeNode;
import ppine.main.LoadedDataHandle;
import ppine.main.PluginDataHandle;
import ppine.ui.PluginMenusHandle;
import ppine.ui.UIController;

public class DefaultLoadingController {

    public static void deleteAllInteractions() {
        DataHandle dh = PluginDataHandle.getDataHandle();
        LoadedDataHandle ldh = PluginDataHandle.getLoadedDataHandle();
        ldh.deleteAll();
        for (SpeciesTreeNode network : dh.getNetworks().values()) {
            network.deleteAllInteractions();
        }

    }

    public static void deleteSpeciesTree() {
        UIController.getInstance().deleteData();
    }

    public static void loadFamiliesTreeData(String filepath, FamiliesLoadingErrorsListener errorListener) {
        AbstractDataReader.getInstance().readFamiliesTree(filepath, errorListener);

        ProjectorInfoCalculator.calculateProjectorInfo();
        UIController.getInstance().initDataView();
    }

    public static void loadAllInteractions(String filepath, Map<String, Double> tresholds, InteractionsLoadingErrorsListener errorListener) {
        AbstractDataReader.getInstance().readAllInteractions(filepath, tresholds, errorListener);
        PluginMenusHandle.getShowLoadedInteractionsButton().setEnabled(true);
    }

    public static void loadSpeciesTreeData(String filepath, SpeciesLoadingErrorsListener errorListener) {

        AbstractDataReader.getInstance().readSpeciesTree(filepath, errorListener);

        UIController.getInstance().initDataView();
    }

    public static void showPPINELogsPanel() {
        DataLoadingErrorsJPanel errorsPanel = new DataLoadingErrorsJPanel();
        JFrame frame = new JFrame("NetworkEvolutionPlugin errors");

        frame.add(errorsPanel);
        frame.pack();
        frame.setLocationRelativeTo(Cytoscape.getDesktop());
        frame.setVisible(true);
    }

    static void loadExperimentsData(String filepath, ExperimentsLoadingErrorsListener errorListener) {
        AbstractDataReader.getInstance().readAllExperiments(filepath, errorListener);
        //PluginMenusHandle.getShowLoadedInteractionsButton().setEnabled(true);
    }
}
